#!/bin/bash -e

function info() {
echo Usage: `basename $0` '5'
exit 1
}

while getopts  ":p:f:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var



# for i in $@; do
    # awk '$2~/^[01]/' $i > $i.clear
    # mv $i.clear $i
# done

# if test "$i" = "1"; then
    # awk 'BEGIN{OFS="\t"}{print $1, $3, $4/100, $5+$6}' *_R1_*cov.txt > beta.raw.$i.txt
# else
    # awk 'BEGIN{OFS="\t"}{print $1, $3, $4/100, $7}' *_R1_*filterread.$i.txt > beta.raw.$i.txt
# fi



# methy_anno_estimate.sh -p$i beta.raw.$i.txt 1,2,3,4



# rf_methy_011017.py $i.b450k.sub.test.txt $i.cg450.beta.pd.txt 200 4

# rf_methy_011017.py $i.b450k.sub.test.txt $i.beta_mean.pd.txt 200 4

# rf_methy_.sh -p$i $i.cg450.beta.txt
# rf_methy_.sh -p$i $i.beta_mean.txt

# bk.sh -tproject/methylation/test/2017-03 *.result.txt predict_score.txt

for i in $@; do 

    if
    *pe.sort.SingleCmet; then
    awk 'BEGIN{OFS="\t"}{print $1, $2, $8, $5}' *pe.sort.SingleCmet > $i.beta.raw.txt
    else

    awk 'BEGIN{OFS="\t"}{print $1, $3, $4/100, $7}' *_R1_*filterread.$i.txt > $i.beta.raw.txt
    fi

    meth_anno.sh -p$i $i.beta.raw.txt 1,2,3,4

    # meth_bam_stat.sh -p$i `ls -t *R1_val*.sort*.bam`

    rf_pre.sh -p$i $i.cg450.beta.txt
    
done

. $cmd_done